#!/bin/bash

BRANCH=`pwd`
TRUNK=../../trunk
. `dirname $0`/svnmerge-setup.sh
# sets up PWD_IS_TRUNK and TRUNK_IS_MODIFIED

if test -n "$PWD_IS_TRUNK"
then
    echo Please execute this in BRANCH directory
    exit 1
fi
        
if test -n "$1"
then
    TRUNK=$1
fi

if test -z "$BRANCH_IS_MODIFIED"
then
    echo MERGE trunk CHANGES:
    echo " $TRUNK"
    echo INTO branch:
    echo " $BRANCH"
    echo CTRL-C to abort, Enter to proceed.
    read junk

    svn update && svnmerge merge -b -s -S $TRUNK
    if test -n "`svn status $BRANCH | egrep -v '^\?'`"
    then
        echo To commit this merge, execute:
        echo " svn commit -F svnmerge-commit-message.txt && rm svnmerge-commit-message.txt"
    else
        echo "No changes it seems"
    fi
else
    printf "\n$BRANCH_IS_MODIFIED\n"
    echo BRANCH $BRANCH seems modified. Pls commit changes.
fi
